var vm = new Vue(
		{
			el : '#rrapp',
			data : {
				q : {},
				showList : true,
				title : null,
				comPaymentHistory : {
					due : null,
					chargingSd : null,
					chargingEd : null,
					paymentMethod : null
				},
			},
			methods : {
				saveOrUpdate : function(event) {
					var url = vm.comPaymentHistory.serialNo == null ? "compaymenthistory/save"
							: "compaymenthistory/update";
					$.ajax({
						type : "POST",
						url : baseURL + url,
						data : JSON.stringify(vm.comPaymentHistory),
						success : function(r) {
							if (r.code === 0) {
								alert('操作成功', function(index) {
									vm.back();
								});
							} else {
								alert(r.msg);
							}
						}
					});
				},
				back : function(event) {
					parent.setSrc("modules/com/compaymenthistory.html");
				}
			}
		});
$('#due').datepicker().on('changeDate.datepicker.amui', function(event) {
	var date = new Date(event.date);
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	if (month < 10) {
		month = '0' + month;
	}
	var day = date.getDate();
	if (day < 10) {
		day = '0' + day;
	}
	$('#due').val(year + '-' + month + '-' + day);
	vm.comPaymentHistory.due = year + '-' + month + '-' + day;
});
$('#chargingSd').datepicker().on('changeDate.datepicker.amui', function(event) {
	var date = new Date(event.date);
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	if (month < 10) {
		month = '0' + month;
	}
	var day = date.getDate();
	if (day < 10) {
		day = '0' + day;
	}
	$('#chargingSd').val(year + '-' + month + '-' + day);
	vm.comPaymentHistory.chargingSd = year + '-' + month + '-' + day;
	getMonth();
});
$('#chargingEd').datepicker().on('changeDate.datepicker.amui', function(event) {
	var date = new Date(event.date);
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	if (month < 10) {
		month = '0' + month;
	}
	var day = date.getDate();
	if (day < 10) {
		day = '0' + day;
	}
	$('#chargingEd').val(year + '-' + month + '-' + day);
	vm.comPaymentHistory.chargingEd = year + '-' + month + '-' + day;
	getMonth();
});
$("#univalent").keyup(function() {
	getAmountPayable();
});
$("#acreage").keyup(function() {
	getAmountPayable();
});
$("#payAmount").keyup(function() {
	$("#payAmountTotal").text($("#payAmount").val());
});
function getMonth() {
	if (!$("#chargingSd").val().match(new RegExp('^[0-9]+-[0-9]+-[0-9]+.*$'))) {
		return;
	}
	if (!$("#chargingEd").val().match(new RegExp('^[0-9]+-[0-9]+-[0-9]+.*$'))) {
		return;
	}
	var startTmp = $("#chargingSd").val().split("-");
	var endTmp = $("#chargingEd").val().split("-");
	var dS = new Date(startTmp[0], startTmp[1] - 1, startTmp[2]);
	var dE = new Date(endTmp[0], endTmp[1] - 1, endTmp[2]);
	if (dE.getTime() - dS.getTime() < 0) {
		alert("计费开始时间不能大于计费结束时间！");
	}
	var distance = (dE.getTime() - dS.getTime()) / (1000 * 60 * 60 * 24 * 30);
	var month = Math.round(distance);
	if (month < 1) {
		month = 1;
	}
	$("#month").text(month);
	getAmountPayable();
}
function getAmountPayable() {
	var univalent = $("#univalent").val();
	if (!univalent.match(new RegExp('^[+-]?\\d+(\\.\\d+)?$'))) {
		return;
	}
	var acreage = $("#acreage").val();
	if (!acreage.match(new RegExp('^[+-]?\\d+(\\.\\d+)?$'))) {
		return;
	}
	var month = $("#month").text();
	if (!month.match(new RegExp('^[+-]?\\d+(\\.\\d+)?$'))) {
		return;
	}
	var amountPayable = parseFloat(univalent) * parseFloat(acreage)
			* parseFloat(month);
	$("#amountPayable").text(amountPayable);
	$("#amountPayableTotal").text(amountPayable);
}